package com.icangya.DAO.impl;

import com.icangya.DAO.IQRcodeOfCSDAO;
import com.icangya.domain.CSQRcode;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Repository
public class QRcodeOfCSDAOImpl extends BaseDAO<CSQRcode> implements IQRcodeOfCSDAO{

    @Override
    public CSQRcode getCSQR() {
        String hql="from CSQRcode cr order by cr.id desc";
        List<CSQRcode> csqrs;
        try{
            csqrs=(List<CSQRcode>) getHibernateTemplate().find(hql);
        }catch (DataAccessException e){
            e.printStackTrace();
            return null;
        }

        return csqrs.get(0);
    }


    @Override
    public Serializable setCSQR(CSQRcode csqr) {
        Serializable res;
        try {
            res=getHibernateTemplate().save(csqr);
        }catch (DataAccessException e){
            e.printStackTrace();
            return 0;
        }
        return res;
    }
}
